package com.zzw.limit.config;

import com.zzw.limit.alg.handler.LimitHandler;
import com.zzw.limit.alg.handler.DefaultLimitHandler;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@EnableConfigurationProperties({LimitProperties.class})
@ComponentScan({"com.zzw.limit.component", "com.zzw.limit.alg"})
public class LimitConfig {

    @Autowired
    private LimitProperties limitProperties;

    @Bean("defaultLimitHandler")
    @ConditionalOnMissingBean(LimitHandler.class)
    public LimitHandler defaultLimitHandler() {
        return new DefaultLimitHandler();
    }

    @Bean
    public LimitProperties limitProperties() {
        return limitProperties;
    }

}